<?php

namespace App\Http\Controllers\User;

use App\Library\User\AddressTrait;

class AddressController extends BaseController
{
    use AddressTrait;
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index(){
        $items = $this->user->addresses()->orderByDesc('isdefault')->orderBy('address_id')->get();
        return $this->view('user.address.address', ['items'=>$items, 'menu'=>'address']);
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function frame()
    {

        $address_id = $this->request->get('address_id');
        $address = [
            'consignee' => '',
            'phone' => '',
            'province' => '',
            'city' => '',
            'district' => '',
            'street' => '',
            'isdefault' => 0,
            'zipcode' => ''
        ];

        if ($address_id) $address = $this->user->addresses()->where('address_id', $address_id)->first();

        $this->assign(compact('address_id', 'address'));
        return $this->view('user.address.frame');
    }
}
